package com.outsourcing.bottle.ui;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ext.SatelliteMenu;
import android.view.ext.SatelliteMenu.SateliteClickedListener;
import android.view.ext.SatelliteMenuItem;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aviary.android.feather.Constants;
import com.aviary.android.feather.FeatherActivity;
import com.google.gson.Gson;
import com.outsourcing.bottle.BasicActivity;
import com.outsourcing.bottle.R;
import com.outsourcing.bottle.db.LoginUserInfoTable;
import com.outsourcing.bottle.domain.CommentEntry;
import com.outsourcing.bottle.domain.LoginUserInfoEntry;
import com.outsourcing.bottle.domain.PictrueInfo;
import com.outsourcing.bottle.domain.PictureEnrty;
import com.outsourcing.bottle.domain.UrlConfig;
import com.outsourcing.bottle.remoteimage.RemoteImageView;
import com.outsourcing.bottle.util.AppContext;
import com.outsourcing.bottle.util.BasicUIEvent;
import com.outsourcing.bottle.util.HttpUtils;
import com.outsourcing.bottle.util.ImageLoader;
import com.outsourcing.bottle.util.ImageThumbnail;
import com.outsourcing.bottle.util.ServiceUtils;
import com.outsourcing.bottle.util.TextUtil;
import com.outsourcing.bottle.util.UICore;
import com.outsourcing.bottle.util.Utility;
import com.outsourcing.bottle.widget.CustomListView;
/**
 * 
 * @author 06peng
 *
 */
public class UserPhotoActivity extends BasicActivity implements BasicUIEvent, OnClickListener, Callback {
	
	private ImageView backView;
	private ImageView uploadView;
	private View contentView;
	
	private ImageView avatarView;
	private TextView nicknameView;
	private ImageView sexView;
	private TextView memoView;
	private TextView timeView;
	
	private ImageView editView;
	private ImageView deleteView;
	private ImageView bigImageView;
	private TextView commentView;
	private TextView locateView;
	private LinearLayout locateLayout;
	private CustomListView listView;
	private View loadMoreView;
	private TextView titleView;
	
	private int visibleLastIndex = 0; // 最后的可视项索引
	public int visibleItemCount; // 当前窗口可见项总数
	
	private int ouid;
	private int picid;
	private int selectedItem;
	
	private final int init_pic_info = 1;
	private final int error = 2;
	private final int delete_pic = 3;
	private final int get_more_pic = 4;
	private int page = 1;
	public static final int upload_photo_requestcode = 5;
	public static final int reply_comment_requestcode = 6;
	public static final int reply_or_update_photo_requestcode = 7;
	
	private static final int TYPE_DTAIL_PHOTO = 7;
	private static final int TYPE_COMMENT_PHOTO = 8;
	private static final int EXEU_LIKE_OP_SUCCESS = 9;
	private static final int EXEU_LIKE_OP_FAILED = 10;
	private static final int EXEU_LIKE_OPERATION = 11;
//	private static final int EXEU_UNLIKE_OPERATION = 12;
	private static final int REQUESTCODE_FOR_DRAW = 13;
	private static final int forward_photo_requestcode = 14;
	private static final int EXEU_DELETE_LOCATION = 15;
	private static final int EXEU_DELETE_LOCATION_SUCCESS = 16;
	private static final int EXEU_DELETE_LOCATION_FAILED = 17;
	private static final int EXEU_DELETE_LOCATION_ROOT = 18;
	private static final int download_image = 19;
	private final int user_baseinfo_notfull = 20;
	private final int complete_info = 21;
	
	private List<CommentEntry> commentList;
	private PictureEnrty picEntry;
	private Handler handler;
	private Bitmap avatarBitmap;
	private Bitmap imageBitmap;
	
	private CommentAdapter adapter;
	private ImageView homeView;
	
	private Button bt_paint_photo;
	private Button bt_forward;
	private Button bt_comment;
	private ImageView iv_like;
	private RelativeLayout rl_button_like;

	private final int menu_uploadphoto = 15;
	private final int menu_exprofile = 14;
	private final int menu_exphoto = 13;
	private final int menu_gainbt = 12;
	private final int menu_sendbt = 11;
	private TextView albumTitleView;
	
	private ImageLoader loader;
	
	@Override
	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setContentView(R.layout.user_photo_root);
		handler = new Handler(this);
		ouid = getIntent().getIntExtra("ouid", 0);
		picid = getIntent().getIntExtra("picid", 0);
//		albumId = getIntent().getIntExtra("albumid", 0);
		loader = new ImageLoader(this, AppContext.BottleTimelineIcon);
		initWidget();
		initSateMenu();
		UICore.eventTask(this, this, init_pic_info, "init_pic_info", null);
	}
	
	private void initWidget() {
		homeView = (ImageView) findViewById(R.id.topbar_home);
		homeView.setOnClickListener(this);
		backView = (ImageView) findViewById(R.id.topbar_back);
		backView.setOnClickListener(this);
		uploadView = (ImageView) findViewById(R.id.topbar_menu);
		uploadView.setImageResource(R.drawable.uploadphoto);
		uploadView.setOnClickListener(this);
		titleView = (TextView) findViewById(R.id.topbar_title);
		titleView.setVisibility(View.INVISIBLE);
		listView = (CustomListView) findViewById(R.id.refresh_view);
		listView.setonRefreshListener(new CustomListView.OnRefreshListener() {
			
			@Override
			public void onRefresh() {
				page = 1;
				UICore.eventTask(UserPhotoActivity.this, UserPhotoActivity.this, init_pic_info, null, null);
			}
		});
		listView.setOnScrollListener(new OnScrollListener() {
			
			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				if (adapter != null) {
					int itemsLastIndex = adapter.getCount() + 2; // 数据集最后一项的索引
					int lastIndex = itemsLastIndex + 1; // 加上底部的loadMoreView项 和 head项
					if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && visibleLastIndex == lastIndex) {
						// 如果是自动加载,可以在这里放置异步加载数据的代码
						System.out.println(">>>>>>>> load more <<<<<<<<<");
						loadMoreView.setVisibility(View.VISIBLE);
						page++;
						UICore.eventTask(UserPhotoActivity.this, UserPhotoActivity.this, get_more_pic, null, null);
					}
				}
			}
			
			@Override
			public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
				listView.setFirstVisiableItem(firstVisibleItem);
				UserPhotoActivity.this.visibleItemCount = visibleItemCount;
				visibleLastIndex = firstVisibleItem + visibleItemCount;
			}
		});
		
		contentView = LayoutInflater.from(this).inflate(R.layout.user_photo_detail, null);
		listView.addHeaderView(contentView);
		
		loadMoreView = LayoutInflater.from(this).inflate(R.layout.refreshable_list_footer, null);
		loadMoreView.setVisibility(View.GONE);
		listView.addFooterView(loadMoreView);
		
		avatarView = (ImageView) contentView.findViewById(R.id.user_photo_detail_avatar);
		nicknameView = (TextView) contentView.findViewById(R.id.user_photo_detail_nickname);
		sexView = (ImageView) contentView.findViewById(R.id.user_photo_detail_sex);
		memoView = (TextView) contentView.findViewById(R.id.user_photo_detail_memo);
		timeView = (TextView) contentView.findViewById(R.id.user_photo_detail_time);
		editView = (ImageView) contentView.findViewById(R.id.user_photo_detail_edit);
		editView.setOnClickListener(this);
		deleteView = (ImageView) contentView.findViewById(R.id.user_photo_detail_delete);
		deleteView.setOnClickListener(this);
		bigImageView = (ImageView) contentView.findViewById(R.id.user_photo_image);
		bigImageView.setVisibility(View.GONE);
		bigImageView.setOnClickListener(this);
		commentView = (TextView) contentView.findViewById(R.id.user_photo_comment_textview);
		albumTitleView = (TextView)contentView.findViewById(R.id.user_photo_album_title);
		locateView = (TextView) contentView.findViewById(R.id.user_photo_locate_textview);
		locateLayout = (LinearLayout) contentView.findViewById(R.id.user_photo_locate_layout);
		locateLayout.setOnClickListener(this);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				selectedItem = arg2 - 2;
				ArrayList<String> choiceList = new ArrayList<String>();
				if (commentList.get(selectedItem).getComment_location() != null && !commentList.get(selectedItem).getComment_location().equals("")) {
					choiceList.add(getString(R.string.bottle_txt_check_location));
				}
				if (commentList.get(selectedItem).getComment_uid() != AppContext.getInstance().getLogin_uid()) {
					choiceList.add(getString(R.string.bottle_txt_reply_comment));
				}
				if (choiceList.size() > 0) {
					String[] chooices = new String[choiceList.size()];
					chooices = choiceList.toArray(chooices);
					doMenuAction(chooices);
				}
			}
		});
		
		/******************新增组件**********************************/
		bt_paint_photo = (Button)findViewById(R.id.user_paint_photo);
		bt_paint_photo.setOnClickListener(this);
		bt_forward = (Button)findViewById(R.id.bt_user_photo_forward);
		bt_forward.setOnClickListener(this);
		bt_comment = (Button)findViewById(R.id.bt_user_photo_comment); 
		bt_comment.setOnClickListener(this);
		
		rl_button_like = (RelativeLayout)findViewById(R.id.rl_button_like);
		rl_button_like.setOnClickListener(this);
		iv_like = (ImageView)findViewById(R.id.comment_button_like_icon);
		
		
	}
	
	private void updateUI() {
		if (picEntry == null) {
			return;
		}
		uploadView.setVisibility(View.VISIBLE);
		homeView.setVisibility(View.VISIBLE);
		findViewById(R.id.user_photo_root_layout).setVisibility(View.VISIBLE);
		((LinearLayout) contentView.findViewById(R.id.user_photo_detail_layout)).setVisibility(View.VISIBLE);
		if (!TextUtils.isEmpty(picEntry.getAlbum_title())) {
			albumTitleView.setVisibility(View.VISIBLE);
			albumTitleView.setText(TextUtil.R("exchange_bt_album") +":"+ picEntry.getAlbum_title());	
			albumTitleView.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
//					Intent intent = new Intent(UserPhotoActivity.this, AlbumsActivity.class);
//					intent.putExtra("ouid", ouid);
//					startActivity(intent);
					Intent intent = new Intent(UserPhotoActivity.this, PhotosActivity.class);
					intent.putExtra("ouid", ouid);
					intent.putExtra("albumid", picEntry.getAlbumid());
					startActivity(intent);
					
				}
			});
		} else {
			albumTitleView.setVisibility(View.GONE);
		}
		nicknameView.setText(picEntry.getNickname());
		if (!TextUtils.isEmpty(picEntry.getMemo())) {
			memoView.setText(TextUtil.R("user_space_pic_memo")+":" + picEntry.getMemo());
			memoView.setVisibility(View.VISIBLE);
		} else {
			memoView.setVisibility(View.GONE);
		}
		if (picEntry.getSex() == 1) {
			sexView.setBackgroundResource(R.drawable.male);
		} else if (picEntry.getSex() == 2) {
			sexView.setBackgroundResource(R.drawable.female);
		}
		
		timeView.setText("#" + picEntry.getPic_time());
		commentView.setText(TextUtil.R("exchange_feed_comment_title")+picEntry.getPic_desc());
		if (picEntry.getPic_location() != null && !picEntry.getPic_location().equals("")) {
			locateLayout.setVisibility(View.VISIBLE);
			locateView.setText(picEntry.getPic_location());
			locateView.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {

					if(picEntry.getLocation_delete_enable() == 1){
						final Context dialogContext = new ContextThemeWrapper(UserPhotoActivity.this, android.R.style.Theme_Light);
						String[] choices = new String[2];
						choices[0] = getString(R.string.bottle_txt_check_location);
						choices[1] = getString(R.string.bottle_txt_clean_location);

						final ListAdapter adapter = new ArrayAdapter<String>(dialogContext, android.R.layout.simple_list_item_1, choices);

						final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
						builder.setTitle(R.string.system_info);
						builder.setSingleChoiceItems(adapter, -1,
							new DialogInterface.OnClickListener() {

								public void onClick(DialogInterface dialog, int which) {
									dialog.dismiss();
									if (which == 0) {
										dialog.dismiss();
										Intent intent = new Intent(UserPhotoActivity.this, MapViewActivity.class);
										intent.putExtra("longitude", picEntry.getPic_lng());
										intent.putExtra("latidute", picEntry.getPic_lat());
										intent.putExtra("location",picEntry.getPic_location());
										startActivity(intent);
									} else {
										UICore.eventTask(UserPhotoActivity.this, UserPhotoActivity.this, EXEU_DELETE_LOCATION_ROOT, "", picEntry);
									}

								}
							});
						builder.create().show();
				} else {
					final Context dialogContext = new ContextThemeWrapper(UserPhotoActivity.this, android.R.style.Theme_Light);
					String[] choices = new String[1];
					choices[0] = getString(R.string.bottle_txt_check_location);

					final ListAdapter adapter = new ArrayAdapter<String>(dialogContext, android.R.layout.simple_list_item_1, choices);

					final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
					builder.setTitle(R.string.system_info);
					builder.setSingleChoiceItems(adapter, -1,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								Intent intent = new Intent(UserPhotoActivity.this, MapViewActivity.class);
								intent.putExtra("longitude", picEntry.getPic_lng());
								intent.putExtra("latidute", picEntry.getPic_lat());
								intent.putExtra("location", picEntry.getPic_location());
								startActivity(intent);
							}
						});
					builder.create().show();
				}
			  }
			});
		} else {
			locateLayout.setVisibility(View.GONE);
		}
		if (picEntry.getOuid() == AppContext.getInstance().getLogin_uid()) {
			editView.setVisibility(View.VISIBLE);
			deleteView.setVisibility(View.VISIBLE);
			uploadView.setVisibility(View.VISIBLE);
//			bt_paint_photo.setVisibility(View.VISIBLE);
		} else {
			uploadView.setVisibility(View.GONE);
			deleteView.setVisibility(View.GONE);
			editView.setVisibility(View.GONE);
//			bt_paint_photo.setVisibility(View.GONE);
		}
		adapter = new CommentAdapter();
		listView.setAdapter(adapter);
		
		if (picEntry.getPic_like_mode() == 0) {
			rl_button_like.setVisibility(View.INVISIBLE);
		} else if (picEntry.getPic_like_mode() == 1) {
			iv_like.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.like_gray2));
		} else if (picEntry.getPic_like_mode() == 2) {
			iv_like.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.like_red2));
		}
		
	}
	
	@Override
	public boolean handleMessage(Message msg) {
		switch (msg.what) {
		case init_pic_info:
			updateUI();
			new Thread() {
				public void run() {
					downloadImage();
				};
			}.start();
			listView.onRefreshComplete();
			break;
		case error:
			onToast((String) msg.obj);
			break;
		case delete_pic:
			onToast((String) msg.obj);
			Intent intent = new Intent(this, PhotosActivity.class);
			setResult(RESULT_OK, intent);
			finish();
			break;
		case get_more_pic:
			if (adapter != null) {
				adapter.notifyDataSetChanged();
			}
			loadMoreView.setVisibility(View.GONE);
			break;
		case EXEU_LIKE_OP_SUCCESS:
			onToast((String) msg.obj);
			iv_like.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.like_red2));
			rl_button_like.setOnClickListener(null);
//			UICore.eventTask(this, this, init_pic_info, "", null);
			break;
		case EXEU_LIKE_OP_FAILED:
			onToast((String) msg.obj);
//			UICore.eventTask(this, this, init_pic_info, "", null);
			break;
		case EXEU_DELETE_LOCATION_SUCCESS:
			onToast((String) msg.obj);
			UICore.eventTask(UserPhotoActivity.this, UserPhotoActivity.this, init_pic_info, "", null);
			break;
		case EXEU_DELETE_LOCATION_FAILED:
			onToast((String) msg.obj);
			break;
		case download_image:
			Bitmap tempBP =  (Bitmap) msg.obj;
			findViewById(R.id.rl_bottle_content_photo).setVisibility(View.VISIBLE);
			findViewById(R.id.pull_to_refresh_progress).setVisibility(View.GONE);
			bigImageView.setVisibility(View.VISIBLE);
			if (avatarBitmap != null) {
				avatarView.setImageBitmap(avatarBitmap);
			}
			if (tempBP != null) {
				bigImageView.setImageBitmap(tempBP);
			}
			break;
		case user_baseinfo_notfull:
			showChoseMes(getString(R.string.exchange_complete_profile_tips), complete_info);
			break;
		default:
			break;
		}
		return false;
	}

	@Override
	public void onClick(View v) {
		if (v == backView) {
			finish();
		}else if (v == homeView) {
			Intent intent = new Intent(this, HomeActivity.class);
			intent.putExtra("currentItem", 1);
			startActivity(intent);
		} else if (v == uploadView) {
			Intent intent = new Intent(this, ExpandEditActivity.class);
			Bundle extras = new Bundle();
			extras.putString("from_type", AppContext.UPLOAD_PHOTO);
			extras.putString("upload_from", "photo_detail");
			extras.putInt("albumid", picEntry.getAlbumid());
			extras.putInt("ouid", picEntry.getOuid());
			intent.putExtras(extras);
			startActivity(intent);
		} else if (v == locateLayout) {
			Intent intent = new Intent(this, MapViewActivity.class);
			intent.putExtra("longitude", picEntry.getPic_lng());
			intent.putExtra("latidute", picEntry.getPic_lat());
			intent.putExtra("location", picEntry.getPic_location());
			startActivity(intent);
		} else if (v == deleteView) {
			showChoseMes(getString(R.string.photo_delte_confirm), delete_pic);
		} else if (v == editView) {
			Intent intent = new Intent(this, ExpandEditActivity.class);
			Bundle extras = new Bundle();
			extras.putString("from_type", AppContext.EDIT_PHOTO);
			extras.putInt("picid", picid);
			extras.putString("photoname", picEntry.getPic_desc());
			intent.putExtras(extras);
			startActivityForResult(intent, reply_or_update_photo_requestcode);
		} 
//		else if (v == replyView) {
//			Intent intent = new Intent(this, ExpandEditActivity.class);
//			Bundle extras = new Bundle();
//			extras.putString("from_type", AppContext.REPLY_PHOTO);
//			extras.putInt("picid", picid);
//			intent.putExtras(extras);
//			startActivityForResult(intent, reply_or_update_photo_requestcode);
//		} 
		else if (v == bigImageView) {
			if (picEntry.getPic_srcpicid()!=0) {
				String choices[] = new String[2];
				choices[0] = getString(R.string.user_space_pic_src);
				choices[1] = getString(R.string.bottle_txt_feed_comment_tuya);
				chooseAction(choices, TYPE_DTAIL_PHOTO);
			} else {
				byte[] tempBytes = null;
				try {
					tempBytes = ServiceUtils.BitmapTobytes(imageBitmap);
				} catch (Exception e) {
					e.printStackTrace();
				}
				Intent bigPicIntent = new Intent(this, PhotoDetailActivity.class);
				bigPicIntent.putExtra("pic_big", picEntry.getPic_url());
				bigPicIntent.putExtra("thumbnail", tempBytes);
				startActivity(bigPicIntent);	
			}
			
		} else if (v == bt_paint_photo) {
			if (imageBitmap == null) {
				return;
			}
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
			byte[] tempBytes = baos.toByteArray();
			
			File file = Utility.getNextFileName();
			FileOutputStream fs = null;
			try {
				fs = new FileOutputStream(file);
				fs.write(tempBytes);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					if (null != fs) {
						fs.close();	
					}
				} catch (IOException e) {
					e.printStackTrace();
				}	
			}
			
			Uri fileUri = Uri.fromFile(file);
			Intent newIntent = new Intent( UserPhotoActivity.this, FeatherActivity.class );
			newIntent.putExtra( "From_Type", Constants.ACTIVITY_DRAW );
			newIntent.setData( fileUri );
			newIntent.putExtra( "API_KEY", Utility.API_KEY );
			newIntent.putExtra( "output", Uri.parse( "file://" +  file.getAbsolutePath() ) );
			newIntent.putExtra( Constants.EXTRA_OUTPUT_FORMAT, Bitmap.CompressFormat.JPEG.name() );
			newIntent.putExtra( Constants.EXTRA_OUTPUT_QUALITY, 100 );
			newIntent.putExtra( Constants.EXTRA_TOOLS_DISABLE_VIBRATION, true );
			final DisplayMetrics metrics = new DisplayMetrics();
			getWindowManager().getDefaultDisplay().getMetrics( metrics );
			int max_size = Math.min( metrics.widthPixels, metrics.heightPixels );
			max_size = (int) ( (double) max_size / 0.8 );
			newIntent.putExtra( "max-image-size", max_size );
			newIntent.putExtra( "effect-enable-borders", true );
//			mSessionId = StringUtils.getSha256( System.currentTimeMillis() + Utility.API_KEY );
//			newIntent.putExtra( "output-hires-session-id", mSessionId );
//			startActivity(newIntent);
			startActivityForResult(newIntent, REQUESTCODE_FOR_DRAW);
			overridePendingTransition(R.anim.translate_right_in, R.anim.translate_left_in);
			
			
		} else if (v == bt_forward) {
			
			if ( ouid == AppContext.getInstance().getLogin_uid()) {
				final Context dialogContext = new ContextThemeWrapper(this, android.R.style.Theme_Light);
				String[] choices = new String[2];
				choices[0] = getString(R.string.bottle_txt_forward_to_friend);
				choices[1] = getString(R.string.bottle_txt_forward_to_platform);
				final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
						android.R.layout.simple_list_item_1, choices);

				final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
				builder.setTitle(R.string.system_info);
				builder.setSingleChoiceItems(adapter, -1,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
								if (which == 0) {
									Intent forwardIntent = new Intent(UserPhotoActivity.this, ChooseFriendActivity.class);
									Bundle forwardBundle = new Bundle();
									forwardBundle.putInt("choose_friend_type", AppContext.CHOOSE_FRIEND_FORWARD_PHOTO_TYPE);
									forwardBundle.putInt("picid", picid);
									forwardBundle.putInt("pic_uid", ouid);
									forwardBundle.putInt("select_mode", 1);
									forwardIntent.putExtras(forwardBundle);
									startActivity(forwardIntent);	
								} else {
									Intent intent = new Intent(UserPhotoActivity.this, ExpandEditActivity.class);
									Bundle extras = new Bundle();
									extras.putString("from_type", AppContext.FORWARD_PHOTO);
									extras.putInt("picid", picid);
									intent.putExtras(extras);
									startActivityForResult(intent, forward_photo_requestcode);								
								}
							}
						});
				builder.create().show();
			} else {
				final Context dialogContext = new ContextThemeWrapper(this, android.R.style.Theme_Light);
				String[] choices = new String[1];
				choices[0] = getString(R.string.bottle_txt_forward_to_platform);
				final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
						android.R.layout.simple_list_item_1, choices);

				final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
				builder.setTitle(R.string.system_info);
				builder.setSingleChoiceItems(adapter, -1,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int which) {
								dialog.dismiss();
									Intent intent = new Intent(UserPhotoActivity.this, ExpandEditActivity.class);
									Bundle extras = new Bundle();
									extras.putString("from_type", AppContext.FORWARD_PHOTO);
									extras.putInt("picid", picid);
									intent.putExtras(extras);
									startActivityForResult(intent, forward_photo_requestcode);								
							}
						});
				builder.create().show();
			}
		
		} else if (v == bt_comment) {
			Intent intent = new Intent(this, ExpandEditActivity.class);
			Bundle extras = new Bundle();
			extras.putString("from_type", AppContext.REPLY_PHOTO);
			extras.putInt("picid", picid);
			intent.putExtras(extras);
			startActivityForResult(intent, reply_or_update_photo_requestcode);
		} else if (v == rl_button_like) {
			UICore.eventTask(this, this, EXEU_LIKE_OPERATION, "", null);
		}

	}
	
	@Override
	public void doSelectChooseEvent(int which, int chooseType) {
		if (chooseType == TYPE_DTAIL_PHOTO) {
			switch (which) {
			case 0:
				Intent intent = new Intent(this, UserPhotoActivity.class);
				intent.putExtra("picid", picEntry.getPic_srcpicid());
				intent.putExtra("ouid", ouid);
				startActivity(intent);
				break;
			case 1:
				Intent bigPicIntent = new Intent(this, PhotoDetailActivity.class);
				bigPicIntent.putExtra("pic_big", picEntry.getPic_tuya_url());
				startActivity(bigPicIntent);
				break;
			default:
				break;
			}
			
		}else if (chooseType == TYPE_COMMENT_PHOTO) {
			
		}
	}
	
	@Override
	public void execute(int mes, Object obj) {
		switch (mes) {
		case init_pic_info:
			initPicInfo();
			break;
		case delete_pic:
			deletePic();
			break;
		case get_more_pic:
			getMoreComment();
			break;
		case EXEU_LIKE_OPERATION:
			likeIOperationPicex(picid);
			break;
		case EXEU_DELETE_LOCATION:
			CommentEntry mEntry = (CommentEntry)obj;
			deleteLocation(String.valueOf(mEntry.getLocation_objtype_2()), String.valueOf(mEntry.getLocation_objid_2()));
			break;
		case EXEU_DELETE_LOCATION_ROOT:
			PictureEnrty mPicEntry = (PictureEnrty)obj;
			deleteLocation(String.valueOf(mPicEntry.getLocation_objtype()), String.valueOf(mPicEntry.getLocation_objid()));
			break;
		default:
			break;
		}
	}

	/**
	 * 
	 * @param objtype 要清除的位置的类型：选择项：（1）瓶子动态的位置信息、（2）交换动态留言的位置信息、（3）照片评论的位置信息、（4）私信的位置信息、（5）照片的位置信息
	 * @param objid objid
	 */
	private void deleteLocation(String objtype,String objid) {
		StringBuffer url = new StringBuffer(UrlConfig.delete_location);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&objtype=" + objtype);
		url.append("&objid=" + objid);
		ServiceUtils.dout("deleteLocation url:" + url.toString());
		try {
			String result = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("deleteLocation result:" + result);
			JSONObject obj = new JSONObject(result);
			JSONObject resultObj = obj.getJSONObject("results");
			int success = resultObj.getInt("success");
			String errmsg = resultObj.getString("errmsg");
			String successmsg = resultObj.getString("successmsg");
			if (success == 1) {
				Message message = handler.obtainMessage(
						EXEU_DELETE_LOCATION_SUCCESS, successmsg);
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_DELETE_LOCATION_FAILED, errmsg);
				handler.sendMessage(message);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void initPicInfo() {
		StringBuffer url = new StringBuffer(UrlConfig.get_pic_info);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&picid=" + picid);
		url.append("&count=20");
		url.append("&page=" + page);
		try {
			String result = HttpUtils.doGet(url.toString());
			if (result != null) {
				Gson gson = new Gson();
				PictrueInfo info = gson.fromJson(result, PictrueInfo.class);
				if (info.getResults().getAuthok() == 0) {
					String errmsg = info.getResults().getErrmsg();
					Message msg = Message.obtain(handler, error, errmsg);
					handler.sendMessage(msg);
				} else {
					picEntry = info.getPic_info();
					commentList = info.getComments_list();
					handler.sendEmptyMessage(init_pic_info);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void downloadImage() {
		avatarBitmap = HttpUtils.getBitmapFromUrl(UserPhotoActivity.this, picEntry.getAvatar());
		imageBitmap = HttpUtils.getBitmapFromUrl(UserPhotoActivity.this, picEntry.getPic_url());
		Bitmap tempBitmap = null;
		if (null != imageBitmap && imageBitmap.getWidth() > CanvasWidth) {
			float scale = ImageThumbnail.reckonThumbnail(
					imageBitmap.getWidth(), imageBitmap.getHeight(), CanvasWidth - 20, 0);
		    tempBitmap = ImageThumbnail.PicZoom(imageBitmap,
					(int) (imageBitmap.getWidth() / scale), (int) (imageBitmap.getHeight() / scale));
		} else {
			tempBitmap = imageBitmap;
		}
		Message message = handler.obtainMessage(download_image, tempBitmap);
		handler.sendMessage(message);
	}
	
	private void getMoreComment() {
		StringBuffer url = new StringBuffer(UrlConfig.get_pic_info);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&picid=" + picid);
		url.append("&count=20");
		url.append("&page=" + page);
		try {
			String result = HttpUtils.doGet(url.toString());
			if (result != null) {
				Gson gson = new Gson();
				PictrueInfo info = gson.fromJson(result, PictrueInfo.class);
				if (info.getResults().getAuthok() == 0) {
					String errmsg = info.getResults().getErrmsg();
					Message msg = Message.obtain(handler, error, errmsg);
					handler.sendMessage(msg);
				} else {
					List<CommentEntry> moreCommentList = info.getComments_list();
					if (moreCommentList != null && !moreCommentList.isEmpty()) {
						commentList.addAll(moreCommentList);
					}
					handler.sendEmptyMessage(get_more_pic);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void deletePic() {
		String url = UrlConfig.delete_pic;
		HashMap<String, String> paramsMap = new HashMap<String, String>();
		paramsMap.put("login_uid", String.valueOf(AppContext.getInstance().getLogin_uid()));
		paramsMap.put("login_token", AppContext.getInstance().getLogin_token());
		paramsMap.put("picid", String.valueOf(picid));
		try {
			String result = HttpUtils.doPost(this, url, paramsMap);
			if (result == null) {
				return;
			}
			JSONObject object = new JSONObject(result);
        	JSONObject resultObj = object.getJSONObject("results");
        	int success = resultObj.getInt("success");
        	if (success == 0) {
        		String errmsg = resultObj.getString("errmsg");
        		Message msg = Message.obtain(handler, error, errmsg);
        		handler.sendMessage(msg);
        	} else {
        		String successmsg = resultObj.getString("successmsg");
				Message msg = Message.obtain(handler, delete_pic, successmsg);
				handler.sendMessage(msg);
        	}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void sysMesPositiveButtonEvent(int what) {
		if (what == delete_pic) {
			UICore.eventTask(this, this, delete_pic, "delete_pic", null);
		} else if (what == complete_info) {
			Intent intent = new Intent(this, SettingActivity.class);
			startActivity(intent);
		} 
	}
	
	public class CommentAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return commentList == null ? 0 : commentList.size();
		}

		@Override
		public Object getItem(int arg0) {
			return commentList == null ? null : commentList.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			return arg0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.user_photo_comment_item, null);
			} 
			RemoteImageView avatar = (RemoteImageView) convertView.findViewById(R.id.user_photo_comment_item_avatar);
			TextView content = (TextView) convertView.findViewById(R.id.user_photo_comment_item_nameandcontent);
			TextView time = (TextView) convertView.findViewById(R.id.user_photo_comment_item_timeandlocattion);
			TextView reply = (TextView) convertView.findViewById(R.id.user_photo_comment_item_reply);
			LinearLayout replyLayout = (LinearLayout) convertView.findViewById(R.id.user_photo_comment_item_reply_layout);
			Button feed_reply_comment = (Button) convertView.findViewById(R.id.feed_reply_comment);
			ImageView up = (ImageView) convertView.findViewById(R.id.user_photo_comment_item_up);
			ImageView mfeedReplyPhoto = (ImageView) convertView.findViewById(R.id.photo);
			RelativeLayout comment_content_photo = (RelativeLayout) convertView.findViewById(R.id.rl_bottle_content_photo);
			ImageView iv_feed_comment_love = (ImageView) convertView.findViewById(R.id.iv_feed_comment_love);
			final CommentEntry entry = commentList.get(position);
			if (entry != null) {
				avatar.setDefaultImage(R.drawable.avatar_default_big);
				avatar.setImageUrl(entry.getComment_avatar(), position, listView);
				String nickName = null;
				if (entry.getComment_uid() != AppContext.getInstance().getLogin_uid()) {
					nickName = (!TextUtils.isEmpty(entry.getComment_nickname())) ? ("<font color='#DA4A37'>"
							+ entry.getComment_nickname()+ "</font>") : "";
				} else {
					nickName = (!TextUtils.isEmpty(entry.getComment_nickname())) ? ("<font color='#3F99D8'>"
							+ entry.getComment_nickname() + "</font>") : "";
				}
				if (TextUtil.notEmpty(entry.getComment_tuyapic_small())) {
					loader.DisplayImage(entry.getComment_tuyapic_small(), mfeedReplyPhoto, R.drawable.album_nophoto);
				} 
				content.setText(Html.fromHtml(nickName + "&nbsp;" + TextUtil.htmlEncode(entry.getComment_content())));
				String timeStr = (!TextUtils.isEmpty(entry.getComment_time()))?("#"+entry.getComment_time()):"";
				String location = (!TextUtils.isEmpty(entry.getComment_location()))?("@"+entry.getComment_location()):"";
				time.setText(timeStr+ " " + location);
				
				if (!TextUtils.isEmpty(location)) {
					time.setOnClickListener(new View.OnClickListener() {
						
						@Override
						public void onClick(View v) {

								if(entry.getLocation_delete_enable_2() == 1){
									final Context dialogContext = new ContextThemeWrapper(
											UserPhotoActivity.this, android.R.style.Theme_Light);
									String[] choices = new String[2];
									choices[0] = getString(R.string.bottle_txt_check_location);
									choices[1] = getString(R.string.bottle_txt_clean_location);

									final ListAdapter adapter = new ArrayAdapter<String>(
											dialogContext, android.R.layout.simple_list_item_1, choices);

									final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
									builder.setTitle(R.string.system_info);
									builder.setSingleChoiceItems(
											adapter,
											-1,
											new DialogInterface.OnClickListener() {

												public void onClick(
														DialogInterface dialog,
														int which) {
													dialog.dismiss();
													if (which == 0) {
														dialog.dismiss();
														Intent intent = new Intent(
																UserPhotoActivity.this,
																MapViewActivity.class);
														intent.putExtra("longitude",
																entry.getComment_lng());
														intent.putExtra("latidute",
																entry.getComment_lat());
														intent.putExtra(
																"location",
																entry.getComment_location());
														startActivity(intent);
													} else {
														UICore.eventTask(UserPhotoActivity.this, UserPhotoActivity.this, EXEU_DELETE_LOCATION, "", entry);
													}

												}
											});
									builder.create().show();
							} else {
								final Context dialogContext = new ContextThemeWrapper(
										UserPhotoActivity.this,
										android.R.style.Theme_Light);
								String[] choices = new String[1];
								choices[0] = getString(R.string.bottle_txt_check_location);

								final ListAdapter adapter = new ArrayAdapter<String>(
										dialogContext,
										android.R.layout.simple_list_item_1,
										choices);

								final AlertDialog.Builder builder = new AlertDialog.Builder(
										dialogContext);
								builder.setTitle(R.string.system_info);
								builder.setSingleChoiceItems(adapter, -1,
										new DialogInterface.OnClickListener() {
											public void onClick(
													DialogInterface dialog,
													int which) {
												dialog.dismiss();
												Intent intent = new Intent(
														UserPhotoActivity.this,
														MapViewActivity.class);
												intent.putExtra("longitude",
														entry.getComment_lng());
												intent.putExtra("latidute",
														entry.getComment_lat());
												intent.putExtra(
														"location",
														entry.getComment_location());
												startActivity(intent);
											}
										});
								builder.create().show();
							}
						}
					});
				}
				
				if (entry.getComment_type() == 1) {
					iv_feed_comment_love.setVisibility(View.VISIBLE);
				} else {
					iv_feed_comment_love.setVisibility(View.GONE);
				}
				
				if (entry.getComment_replycomment() != null && !entry.getComment_replycomment().equals("")) {
					up.setVisibility(View.VISIBLE);
					replyLayout.setVisibility(View.VISIBLE);
					reply.setText(entry.getComment_replycomment());
				} else {
					replyLayout.setVisibility(View.GONE);
					up.setVisibility(View.GONE);
				}
				
				if (entry.getComment_uid() != AppContext.getInstance()
						.getLogin_uid()&&entry.getComment_type() == 0) {
						feed_reply_comment.setVisibility(View.VISIBLE);
						feed_reply_comment.setOnClickListener(new OnClickListener() {
							
							@Override
							public void onClick(View v) {
								Intent commentIntent = new Intent(UserPhotoActivity.this,ExpandEditActivity.class);
								Bundle commentBundle = new Bundle();
								commentBundle.putString("from_type",AppContext.REPLY_COMMENT);
								commentBundle.putString("return_type",UserPhotoActivity.class.getSimpleName());
								commentBundle.putInt("commentid",entry.getCommentid());
								commentIntent.putExtras(commentBundle);
								startActivityForResult(commentIntent,0);
							}
						});
					}else {
						feed_reply_comment.setVisibility(View.GONE);
					}
				
				if (!TextUtils.isEmpty(entry.getComment_tuyapic_small())) {
					comment_content_photo.setVisibility(View.VISIBLE);
					mfeedReplyPhoto.setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View paramView) {
							String choices[] = new String[2];
							choices[0] = getString(R.string.user_space_pic_src);
							choices[1] = getString(R.string.bottle_txt_feed_comment_tuya);
							final Context dialogContext = new ContextThemeWrapper(UserPhotoActivity.this, android.R.style.Theme_Light);
							String cancel = getString(R.string.bt_title_back);
							final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
									android.R.layout.simple_list_item_1, choices);

							final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
							builder.setTitle(R.string.system_info);
							builder.setSingleChoiceItems(adapter, -1,
									new DialogInterface.OnClickListener() {
										public void onClick(DialogInterface dialog, int which) {
											dialog.dismiss();
											switch (which) {
											case 0:
												Intent intent = new Intent(UserPhotoActivity.this, UserPhotoActivity.class);
												intent.putExtra("picid", entry.getComment_tuyapicid());
												intent.putExtra("ouid", entry.getComment_uid());
												startActivity(intent);
												break;
											case 1:
												Intent bigPicIntent = new Intent(UserPhotoActivity.this, PhotoDetailActivity.class);
												bigPicIntent.putExtra("pic_big", entry.getComment_tuyapic_tuya());
												startActivity(bigPicIntent);
												break;
											}
										}
									});
							builder.setNegativeButton(cancel,
									new DialogInterface.OnClickListener() {

										@Override
										public void onClick(DialogInterface dialog, int which) {
											dialog.dismiss();
										}

									});
							builder.create().show();
						}
					});
				}else {
					comment_content_photo.setVisibility(View.GONE);
				}
				
				
			}
			avatar.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent spaceIntent = new Intent(UserPhotoActivity.this, UserSpaceActivity.class);
					spaceIntent.putExtra("ouid", entry.getComment_uid());
					startActivity(spaceIntent);
				}
			});
			return convertView;
		}
	}
	
	public static class ViewHolder {
		ImageView avatar;
		TextView content;
		TextView time;
		LinearLayout replyLayout;
		TextView reply;
		ImageView up;
	}
	
	
	@Override
	protected void onResume() {
		super.onResume();
		if(AppContext.getInstance().isFromUserPhotoActivity()){
			AppContext.getInstance().setFromUserPhotoActivity(false);
			page = 1;
			UICore.eventTask(this, this, init_pic_info, "", null);
		}
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int arg1, Intent intent) {
		if (arg1 == RESULT_OK) {
			if (null != intent) {
				if (intent.getBooleanExtra("need_refresh", false)) {
					UICore.eventTask(this, this, init_pic_info, "init_pic_info", null);
				}
			}
			
			if (requestCode == upload_photo_requestcode) {
				UICore.eventTask(this, this, init_pic_info, "init_pic_info", null);
			} else if (requestCode == reply_comment_requestcode) {
				UICore.eventTask(this, this, init_pic_info, "init_pic_info", null);
			} else if (requestCode == reply_or_update_photo_requestcode) {
				UICore.eventTask(this, this, init_pic_info, "init_pic_info", null);
			} else if (requestCode == forward_photo_requestcode) {
				UICore.eventTask(this, this, init_pic_info, "init_pic_info", null);
			}
			
			if (requestCode == REQUESTCODE_FOR_DRAW) {
				Intent commentIntent = new Intent(this,
						ExpandEditActivity.class);
				Bundle commentBundle = new Bundle();
				commentBundle.putString("from_type",
						AppContext.PAINT_PHOTO);
				commentBundle.putInt("picid", picid);
				commentIntent.putExtras(commentBundle);
				startActivity(commentIntent);
			}
		}
	
		
		super.onActivityResult(requestCode, arg1, intent);
	}
	
	private void doMenuAction(String[] choices) {
		final Context dialogContext = new ContextThemeWrapper(UserPhotoActivity.this, android.R.style.Theme_Light);
		String cancel = getString(R.string.bt_title_back);
		final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
				android.R.layout.simple_list_item_1, choices);

		final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
		builder.setTitle(R.string.system_info);
		builder.setSingleChoiceItems(adapter, -1,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						CommentEntry entry = commentList.get(selectedItem);
						switch (which) {
						case 0:
							Intent intent = new Intent(UserPhotoActivity.this, MapViewActivity.class);
							if (entry.getComment_location() != null && !entry.getComment_location().equals("")) {
								intent.putExtra("longitude", entry.getComment_lng());
								intent.putExtra("latidute", entry.getComment_lat());
								intent.putExtra("location", entry.getComment_location());
								startActivity(intent);
							} else if (entry.getCommentid() != AppContext.getInstance().getLogin_uid()) {
								Intent reply_intent = new Intent(UserPhotoActivity.this, ExpandEditActivity.class);
								Bundle extras = new Bundle();
								extras.putString("from_type", AppContext.REPLY_COMMENT);
								extras.putString("return_type", "userphotoactivity");
								extras.putInt("commentid", entry.getCommentid());
								reply_intent.putExtras(extras);
								startActivityForResult(reply_intent, reply_comment_requestcode);
							}
							break;
						case 1:
							if (entry != null) {
								Intent reply_intent = new Intent(UserPhotoActivity.this, ExpandEditActivity.class);
								Bundle extras = new Bundle();
								extras.putString("from_type", AppContext.REPLY_COMMENT);
								extras.putInt("commentid", entry.getCommentid());
								reply_intent.putExtras(extras);
								startActivityForResult(reply_intent, reply_comment_requestcode);
							}
							break;
						}
					}
				});
		builder.setNegativeButton(cancel,
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}

				});
		builder.create().show();
	}
	
	
	
	private void likeIOperationPicex(int picid) {
		StringBuffer url = new StringBuffer(UrlConfig.like_photo);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&picid=" + picid);

		ServiceUtils.dout("likeIOperationPicex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("likeIOperationPicex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_LIKE_OP_SUCCESS, successmsg);
					handler.sendMessage(message);
				} else {
					Message message = handler.obtainMessage(
							EXEU_LIKE_OP_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
//	View view = null;
//	private View mLikeView;
//	private CustomPopupWindow mLikePopview;
//	
//	/** 喜欢pop */
//	private void initLikePopupWindow() {
//
//		LayoutInflater mLayoutInflater = LayoutInflater.from(this);
//		mLikeView = mLayoutInflater.inflate(R.layout.pop_bottle_like_left, null);
//		ImageView iv_unlike = (ImageView) mLikeView
//				.findViewById(R.id.iv_unlike);
//		ImageView iv_like = (ImageView) mLikeView.findViewById(R.id.iv_like);
//		iv_unlike.setOnClickListener(this);
//		iv_like.setOnClickListener(this);
//		mLikePopview = new CustomPopupWindow(mLikeView,
//				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//		mLikePopview.setBackgroundDrawable(getResources().getDrawable(
//				R.drawable.ic_launcher));
//		mLikePopview.setOutsideTouchable(true);
//		mLikePopview.update();
//		mLikePopview.setTouchable(true);
//		mLikePopview.setFocusable(true);
//	}
//	
//	public void showInfoPopupWindow(View achorView, int picid) {
//		this.picid = picid;
//		if (mLikePopview.isShowing()) {
//			mLikePopview.dismiss();
//		} else {
//			// mLikePopview.showAtLocation(achorView, Gravity.RIGHT, 0, 0);
//			mLikePopview.showAsDropDown(achorView, 60, -60);
//		}
//	}
	
	SatelliteMenu menu;
	private void initSateMenu() {
		if (menu == null) {
			LinearLayout layout = (LinearLayout) findViewById(R.id.menu_layout);
			menu = new SatelliteMenu(this);
//			menu.setExpandDuration(500);
			if (CanvasWidth >= 480) {
				menu.setSatelliteDistance(200);
			} else {
				menu.setSatelliteDistance(100);
			}
			menu.setTotalSpacingDegree(90.0f);
			menu.setCloseItemsOnClick(true);
			layout.addView(menu);
			
			List<SatelliteMenuItem> items = new ArrayList<SatelliteMenuItem>();
			items.add(new SatelliteMenuItem(menu_exprofile, R.drawable.menu_exprofile));
			items.add(new SatelliteMenuItem(menu_exphoto, R.drawable.menu_exphoto));
			items.add(new SatelliteMenuItem(menu_gainbt, R.drawable.menu_gainbt));
			items.add(new SatelliteMenuItem(menu_sendbt, R.drawable.menu_sendbt));
			items.add(new SatelliteMenuItem(menu_uploadphoto, R.drawable.menu_uploadphoto));
			menu.addItems(items);
		}
		menu.setOnItemClickedListener(new SateliteClickedListener() {

			public void eventOccured(int id) {
				switch (id) {
				case menu_sendbt: //扔瓶子
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent throwIntent = new Intent(UserPhotoActivity.this, ChooseBottleActivity.class);
								throwIntent.putExtra("type", "throw");
								startActivity(throwIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_gainbt: //捞瓶子
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent tryIntent = new Intent(UserPhotoActivity.this, ChooseBottleActivity.class);
								tryIntent.putExtra("type", "try");
								startActivity(tryIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_exphoto:  //交换照片
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent exchangeInfoIntent = new Intent(UserPhotoActivity.this, ChooseFriendActivity.class);
								exchangeInfoIntent.putExtra("choose_friend_type", AppContext.CHOOSE_FRIEND_EXCHANGE_PHOTO_TYPE);
								startActivity(exchangeInfoIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_exprofile: //交换资料
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								LoginUserInfoTable userTable = new LoginUserInfoTable();
								LoginUserInfoEntry userEntry = userTable.getLoginUserInfo(AppContext.getInstance().getLogin_uid());
								if (userEntry.getBasicinfo_fullfill() == 0) {
									handler.sendEmptyMessage(user_baseinfo_notfull);
								} else {
									Intent exchangeFileIntent = new Intent(UserPhotoActivity.this, ChooseFriendActivity.class);
									exchangeFileIntent.putExtra("choose_friend_type", AppContext.CHOOSE_FRIEND_EXCHANGE_INFO_TYPE);
									startActivity(exchangeFileIntent);
								}
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_uploadphoto:
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent intent = new Intent(UserPhotoActivity.this, ExpandEditActivity.class);
								Bundle extras = new Bundle();
								extras.putString("from_type", AppContext.UPLOAD_PHOTO);
								extras.putInt("albumid", 0);
								extras.putInt("ouid", AppContext.getInstance().getLogin_uid());
								intent.putExtras(extras);
								startActivity(intent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				default:
					break;
				}
			}
		});
	}
	
}
